define(["jquery", "easy-admin"], function ($, ea) {

    let id = ['currentTable1','currentTable2','currentTable3','currentTable4']
    var operat = ['edit', 'delete'];

    // //select 1: 查询出售中、仓库中、已售空商品 2: 查询回收站商品
    // var select = 1;

    var Controller = {
        index: function () {
            let i;
            let len = id.length;
            for (i = 0; i < len; i++) {
                let keyword = i+1;
                if (keyword == 4) {
                    operat = ['restore', 'forceDelete'];
                }

                ea.table.render({
                    init: {
                        table_elem: "#"+id[i],
                        table_render_id: 'currentTableRenderId'+i,
                        index_url: 'store.goods/index?keyword='+keyword,
                        add_url: 'store.goods/add',
                        edit_url: 'store.goods/edit',
                        delete_url: 'store.goods/delete',
                        force_delete_url: 'store.goods/forceDelete',
                        restore_url: 'store.goods/restore',
                        export_url: 'store.goods/export',
                        modify_url: 'store.goods/modify',
                    },
                    cols: [[
                        {type: 'checkbox'},
                        {field: 'id', title: '主键id', search: false},
                        {field: 'goods_name', title: '商品名称'},
                        {field: 'image', title: '商品logo', templet: ea.table.image, search: false},
                        {field: 'goods_price', title: '商品价格', search: false},
                        {field: 'is_status', title: '是否上架', selectList: {0: '上架', 1: '下架'}, templet: ea.table.switch, search: false},
                        {field: 'sort', title: '排序', edit: 'text', search: false},
                        {field: 'goods_stock', title: '商品库存', search: false},
                        {field: 'create_time', title: '创建时间', search: false},
                        {width: 250, title: '操作', templet: ea.table.recycleTool, operat}
                    ]],
                });
            }

            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
    };


    var active = {
        reload: function () {
            //获得选项卡数据status  1：出售中  2：仓库中  3：已售空  4：回收站
            status = $(this).attr('value');
            console.log(status);
            //执行重载
            ea.table.reload('currentTableRenderId'+status, status);
        }
    };

    // $(".layui-tab-item").click(function () {
    //     active["reload"].call(this);
    // })

    return Controller;
});